package com.jse.websocket;

import javax.websocket.CloseReason;
import javax.websocket.EndpointConfig;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.plugins.mvc.websocket.AbstractWsEndpoint;
import org.nutz.plugins.mvc.websocket.NutWsConfigurator;
import org.nutz.plugins.mvc.websocket.WsHandler;

@ServerEndpoint(value = "/websocket", configurator = NutWsConfigurator.class)
@IocBean
public class Websocket extends AbstractWsEndpoint {

	private final Log log = Logs.get();

	@Override
	public WsHandler createHandler(Session session, EndpointConfig config) {
		return super.createHandler(session, config);
	}

	@Override
	public void onOpen(Session session, EndpointConfig config) {
		super.onOpen(session, config);
		log.info(config.getDecoders());
	}

	@Override
	public void onClose(Session session, CloseReason closeReason) {
		super.onClose(session, closeReason);
		log.debug("测试点二; session :" + session + ", closeReason:" + closeReason);
	}

	@Override
	public void onError(Session session, Throwable throwable) {
		super.onError(session, throwable);
		log.debug("测试点三; session :" + session + ", throwable:" + throwable);
	}

	public void onMessage(Session session, Object msg) {
		log.debug("测试点4; session :" + session + ", msg:" + msg);
	}

}